/**
 * @file Pictures.as
 *  显示图片效果页面
 * @author db0@qq.com
 * @version 1.0.1
 * @date 2017-10-31
 */
package zhuhai
{
	import flash.display.Bitmap;
	import flash.display.Stage;
	import flash.display.Sprite;
	import flash.filesystem.File;
	import flash.events.Event;
	
	public class Pictures extends Sprite
	{
		private static var header:Header;
		
		public function Pictures()
		{
			header = new Header("图片");
			addChild(header);
		}
		
		private function quit(e:Event):void
		{
			MyKey.main.removeEventListener(MyKey.CLICK, quit);
			if (stage == null || !main.visible)
				return;
			main.visible = false;
			if (circle)
			{
				container.removeChild(circle);
				ViewSet.removes(circle);
				circle = null;
			}
			Main.show();
		}
		private static var _main:Pictures;
		
		private static function get main():Pictures
		{
			if (_main == null)
				_main = new Pictures;
			return _main;
		}
		private static var circle:Circle;
		
		/* -----------------------------------------------*/
		/**
		 *  
		 *
		 * @param file:File	文件夹
		 * @param bgURL:String	背景图URL
		 * @param pictureArr:String	图片URL列表数组
		 * 显示图片浏览
		 * @return  
		 */
		public static function show(file:File,bgURL:String,pictureArr:Array):void
		{
			//添加到舞台并显示
			var _stage:Stage = Main.main.stage;
			_stage.addChild(main);
			main.visible = true;

			//显示标题
			header.setTitle(file.name);
			
			//显示图片容器
			main.addCircle(pictureArr);//
			
			MyKey.main.addEventListener(MyKey.CLICK, main.quit);
			
			//删除旧背景
			if (bgBmp)
			{
				if (main.contains(bgBmp))
					main.removeChild(bgBmp);
				bgBmp.bitmapData.dispose();
				bgBmp = null;
			}
			//加载显示新旧背景
			if (pictureArr)
			{
				SwfLoader.SwfLoad(bgURL, main.addBg);
			}
		}
		
		private static var bgBmp:Bitmap;
		
		private function addBg(e:Event):void
		{
			
			if (e && e.type == Event.COMPLETE)
			{
				bgBmp = e.target.content as Bitmap;
				//ViewSet.fullCenter(bgBmp, 0, 0, Main.stageWidth, Main.stageHeight);
				//ViewSet.center(bgBmp, 0, 0, Main.stageWidth, Main.stageHeight);
				ViewSet.fullFill(bgBmp, Main.stageWidth, Main.stageHeight);
				addChildAt(bgBmp,0);
			}
		}
		
		private var container:Sprite;
		private  function addCircle(pictureArr:Array):void
		{
			if (container == null)
			{
				container = new Sprite();
				addChild(container);
			}
		
			circle = new Circle(pictureArr);
			container.addChild(circle);
		}
	
	}
}
